home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ham Radio 2000
/
Ham Radio 2000.iso
/
ham2000
/
satellit
/
im2gif
/
clip.c
next >
Wrap
Text File
|
1991-11-24
|
2KB
|
101 lines
/* Clip rows and columes, assume 612 columes
clip rows columes
rows = number of rows to skip from top of image
columes = nummber of pixels to skip from left side
NK6K
*/
#include <stdio.h>
#include <dos.h>
#include <fcntl.h>
#include <sys\types.h>
#include <sys\stat.h>
#define LINE_SIZE 612
#define NUM_LINE_FIELD 288
long start_field_2;
int lines=0;
int skip_lines=0;
int skip_cols = 0;
char buff[LINE_SIZE];
int fillval=0;
int line_size;
main(argc,argv)
int argc;
char *argv[];
{
int fi1,fi2,fo;
int i,insize;
if (argc<2) {
printf ("usage: clip in out row col\n");
printf ("row - number of lines from top to remove\n");
printf ("col - number of columes from left to remove\n");
exit(1);
}
skip_lines = atoi(argv[3]);
skip_cols = atoi(argv[4]);
if (argc>5) line_size = atoi(argv[5]);
else line_size = LINE_SIZE;
if ((fi1= open(argv[1], O_BINARY)) == -1){
printf("cannot open: %s\n",argv[1]);
perror("On input file");
exit(1);
}
if ((fo = open(argv[2], 0)) != -1){
printf("output file exists. Aborted\n");
exit(1);
}
if ((fo = open(argv[2],O_CREAT | O_TRUNC | O_BINARY | O_RDWR, S_IREAD | S_IWRITE)) == -1) {
printf("cannot open: %s\n",argv[2]);
perror("On output file");
exit(1);
}
buff[LINE_SIZE]=0;
while (1) {
if (read(fi1, buff, line_size)<line_size) {
break;
}
if (lines >= skip_lines) {
if (skip_cols>0) {
if (write(fo,buff+skip_cols,line_size-skip_cols)==-1) {
perror("On output file 1st field\n");
exit(1);
}
}
else if (write(fo,buff,line_size+skip_cols)==-1) {
perror("On output file 1st field\n");
exit(1);
}
}
lines++;
}
close (fo);
close (fi1);
}